package com.aspose.cells.b.a.d;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class zh extends zm {
   private byte[] b;
   private int c;
   private int d;
   private int e;
   private int f;
   private boolean g;
   private boolean h;
   private boolean i;
   private boolean j;

   public void a(int var1) {
      this.d = var1;
   }

   public int i_() {
      return this.e - this.c;
   }

   public zh() {
      this(0);
   }

   public zh(InputStream var1) throws Exception {
      this(0);

      while(true) {
         byte[] var2 = new byte[2048];
         int var3 = var1.read(var2, 0, var2.length);
         if (var3 == -1) {
            this.d = 0;
            return;
         }

         this.b(var2, 0, var3);
      }
   }

   public zh(int var1) {
      if (var1 < 0) {
         throw new IllegalArgumentException("capacity");
      } else {
         this.b = new byte[var1];
         this.f = var1;
         this.g = true;
         this.h = true;
         this.i = true;
         this.c = 0;
         this.j = true;
      }
   }

   public zh(byte[] var1) {
      this(var1, true);
   }

   public zh(byte[] var1, boolean var2) {
      if (var1 == null) {
         throw new NullPointerException("buffer");
      } else {
         this.b = var1;
         this.e = this.f = var1.length;
         this.h = var2;
         this.i = true;
         this.c = 0;
         this.j = true;
      }
   }

   public zh(byte[] var1, int var2, int var3) {
      this(var1, var2, var3, true, true);
   }

   public zh(byte[] var1, int var2, int var3, boolean var4, boolean var5) {
      if (var1 == null) {
         throw new NullPointerException("buffer");
      } else if (var2 < 0) {
         throw new IllegalArgumentException("index");
      } else if (var3 < 0) {
         throw new IllegalArgumentException("count");
      } else if (var1.length - var2 < var3) {
         throw new IllegalArgumentException("The buffer length minus index is less than count.");
      } else {
         this.b = var1;
         this.c = this.d = var2;
         this.e = this.f = var2 + var3;
         this.h = var4;
         this.i = var5;
         this.g = false;
         this.j = true;
      }
   }

   public boolean d() {
      return true;
   }

   public boolean e() {
      return true;
   }

   public boolean f() {
      return this.h;
   }

   public void a() throws IOException {
      this.h = false;
      this.g = false;
   }

   public void b() throws Exception {
   }

   private boolean c(int var1) throws IOException {
      if (var1 < 0) {
         throw new IllegalArgumentException("value");
      } else if (var1 > this.f) {
         int var2 = var1;
         if (var1 < 256) {
            var2 = 256;
         }

         if (var2 < this.f << 1) {
            var2 = this.f << 1;
         }

         this.b(var2);
         return true;
      } else {
         return false;
      }
   }

   public byte[] m() {
      if (!this.i) {
         throw new UnsupportedOperationException("UnauthorizedAccess_MemStreamBuffer");
      } else {
         return this.b;
      }
   }

   public int n() throws IOException {
      if (!this.j) {
         this.p();
      }

      return this.f - this.c;
   }

   public void b(int var1) throws IOException {
      if (!this.j) {
         this.p();
      }

      if (var1 != this.f) {
         if (!this.g) {
            throw new UnsupportedOperationException("This stream is not expandable.");
         }

         if (var1 < this.e) {
            throw new IllegalArgumentException("capacity");
         }

         if (var1 > 0) {
            byte[] var2 = new byte[var1];
            if (this.e > 0) {
               System.arraycopy(this.b, 0, var2, 0, this.e);
            }

            this.b = var2;
         } else {
            this.b = null;
         }

         this.f = var1;
      }

   }

   public long h() throws IOException {
      if (!this.j) {
         this.p();
      }

      return (long)(this.e - this.c);
   }

   public long i() throws IOException {
      if (!this.j) {
         this.p();
      }

      return (long)(this.d - this.c);
   }

   public void b(long var1) throws IOException {
      if (!this.j) {
         this.p();
      }

      if (var1 < 0L) {
         throw new IllegalArgumentException("length");
      } else if (var1 > 2147483647L) {
         throw new IllegalArgumentException("length");
      } else {
         this.d = this.c + (int)var1;
      }
   }

   public long a(long var1, int var3) throws IOException {
      switch(var3) {
      case 0:
         this.b(var1);
         break;
      case 1:
         this.b(this.i() + var1);
         break;
      case 2:
         this.b(this.h() + var1);
         break;
      default:
         throw new IllegalStateException("Unknown SeekOrigin type.");
      }

      assert this.d >= 0;

      return (long)this.d;
   }

   public int a(byte[] var1, int var2, int var3) throws IOException {
      if (!this.j) {
         this.p();
      }

      if (var1 == null) {
         throw new NullPointerException("buffer");
      } else if (var2 < 0) {
         throw new IllegalArgumentException("offset");
      } else if (var3 < 0) {
         throw new IllegalArgumentException("count");
      } else if (var1.length - var2 < var3) {
         throw new IllegalArgumentException("The buffer length minus index is less than count.");
      } else {
         int var4 = this.e - this.d;
         if (var4 > var3) {
            var4 = var3;
         }

         if (var4 <= 0) {
            return 0;
         } else {
            assert this.d + var4 >= 0 : "_position + n >= 0";

            if (var4 <= 8) {
               int var5 = var4;

               while(true) {
                  --var5;
                  if (var5 < 0) {
                     break;
                  }

                  var1[var2 + var5] = this.b[this.d + var5];
               }
            } else {
               System.arraycopy(this.b, this.d, var1, var2, var4);
            }

            this.d += var4;
            return var4;
         }
      }
   }

   public int c() throws IOException {
      if (!this.j) {
         this.p();
      }

      return this.d >= this.e ? -1 : this.b[this.d++] & 255;
   }

   public void a(long var1) throws IOException {
      if (!this.h) {
         this.q();
      }

      if (var1 > 2147483647L) {
         throw new IllegalArgumentException("value");
      } else if (var1 >= 0L && var1 <= (long)(Integer.MAX_VALUE - this.c)) {
         int var3 = this.c + (int)var1;
         boolean var4 = this.c(var3);
         if (!var4 && var3 > this.e) {
            com.aspose.cells.b.a.za.a((byte[])this.b, this.e, var3 - this.e, (byte)0);
         }

         this.e = var3;
         if (this.d > var3) {
            this.d = var3;
         }

      } else {
         throw new IllegalArgumentException("value");
      }
   }

   public byte[] o() {
      byte[] var1 = new byte[this.e - this.c];
      System.arraycopy(this.b, this.c, var1, 0, this.e - this.c);
      return var1;
   }

   public void b(byte[] var1, int var2, int var3) throws IOException {
      if (!this.j) {
         this.p();
      }

      if (!this.h) {
         this.q();
      }

      if (var1 == null) {
         throw new NullPointerException("buffer");
      } else if (var2 < 0) {
         throw new IllegalArgumentException("offset");
      } else if (var3 < 0) {
         throw new IllegalArgumentException("count");
      } else if (var1.length - var2 < var3) {
         throw new IllegalArgumentException("Argument_InvalidOffLen");
      } else {
         int var4 = this.d + var3;
         if (var4 < 0) {
            throw new IOException("StreamTooLong");
         } else {
            if (var4 > this.e) {
               boolean var5 = this.d > this.e;
               if (var4 > this.f) {
                  boolean var6 = this.c(var4);
                  if (var6) {
                     var5 = false;
                  }
               }

               if (var5) {
                  com.aspose.cells.b.a.za.a((byte[])this.b, this.e, var4 - this.e, (byte)0);
               }

               this.e = var4;
            }

            if (var3 <= 8) {
               int var7 = var3;

               while(true) {
                  --var7;
                  if (var7 < 0) {
                     break;
                  }

                  this.b[this.d + var7] = var1[var2 + var7];
               }
            } else {
               System.arraycopy(var1, var2, this.b, this.d, var3);
            }

            this.d = var4;
         }
      }
   }

   public void a(byte var1) throws IOException {
      if (!this.j) {
         this.p();
      }

      if (!this.h) {
         this.q();
      }

      if (this.d >= this.e) {
         int var2 = this.d + 1;
         boolean var3 = this.d > this.e;
         if (var2 >= this.f) {
            boolean var4 = this.c(var2);
            if (var4) {
               var3 = false;
            }
         }

         if (var3) {
            com.aspose.cells.b.a.za.a(this.b, this.e, this.d - this.e);
         }

         this.e = var2;
      }

      this.b[this.d++] = var1;
   }

   public void a(OutputStream var1) throws Exception {
      var1.write(this.b, this.c, this.e - this.c);
      var1.flush();
   }

   public void a(zm var1) throws Exception {
      if (!this.j) {
         this.p();
      }

      if (var1 == null) {
         throw new IllegalArgumentException("stream");
      } else {
         var1.b(this.b, this.c, this.e - this.c);
         var1.b();
      }
   }

   private void p() throws IOException {
      throw new IOException("The stream is closed.");
   }

   private void q() {
      throw new UnsupportedOperationException("The stream does not support write operations.");
   }

   public String toString() {
      return "";
   }
}
